package com.woniuxy.ticketmovie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.ticketmovie.entity.MovieType;
import com.woniuxy.ticketmovie.entity.TicketMovie;
import com.woniuxy.ticketmovie.mapper.MovieMapper;
import com.woniuxy.ticketmovie.mapper.MovieTypeMapper;
import com.woniuxy.ticketmovie.mapper.TypeMapper;
import com.woniuxy.ticketmovie.service.MovieService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName MovieServiceImpl
 * @Description TODO
 * @Author zx
 * @Date 2021-02-22 19:31:38
 * @Version 1.0
 */
@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, TicketMovie> implements MovieService {

    @Resource
    private MovieMapper movieMapper;

    @Resource
    private TypeMapper typeMapper;

    @Resource
    private MovieTypeMapper movieTypeMapper;

    @Override
    public void add(TicketMovie movie, int[] typeIds) {
        movieMapper.insert(movie);

        for (int typeId : typeIds) {
            MovieType movieType = new MovieType();
            movieType.setMovieId(movie.getId());
            movieType.setTypeId(typeId);
            movieTypeMapper.insert(movieType);
        }
    }
}
